package com.zqq.goods.service.repository

import com.zqq.baselibrary.http.RetrofitFactory
import com.zqq.baselibrary.http.rx.BaseResp
import com.zqq.goods.service.api.CartApi
import com.zqq.goods.service.bean.AddCartReq
import com.zqq.goods.service.bean.CartGoods
import com.zqq.goods.service.bean.DeleteCartReq
import com.zqq.goods.service.bean.SubmitCartReq
import rx.Observable
import java.util.*
import javax.inject.Inject

/**
 * 购物车数据层
 * wc
 * @author zqq on 2018/8/5.
 */
class CartRepository @Inject constructor() {

    /*-1.获取购物车列表-*/
    fun getCartList(): Observable<BaseResp<MutableList<CartGoods>?>> {
        return RetrofitFactory.instance
                .create(CartApi::class.java)
                .getCartList()
    }


    /*        添加商品到购物车   */
    fun addCart(goodsId: Int, goodsDesc: String, goodsIcon: String, goodsPrice: Long,
                goodsCount: Int, goodsSku: String): Observable<BaseResp<Int>> {
        return RetrofitFactory.instance
                .create(CartApi::class.java)
                .addCart(AddCartReq(goodsId, goodsDesc, goodsIcon, goodsPrice, goodsCount, goodsSku))
    }

    /*        添加商品到购物车 （用Map）  */
    fun addCart(map: Map<String, Any>): Observable<BaseResp<Int>> {
        return RetrofitFactory.instance
                .create(CartApi::class.java)
                .addCart(map)
    }


    /**删除购物车商品*/
    fun deleteCartList(list: List<Int>): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(CartApi::class.java)
                .deleteCartList(DeleteCartReq(list))
    }


    /*
       购物车结算
    */
    fun submitCart(list: MutableList<CartGoods>, totalPrice: Long): Observable<BaseResp<Int>> {
        return RetrofitFactory.instance
                .create(CartApi::class.java)
                .submitCart(SubmitCartReq(list, totalPrice))
    }


}